Correctly preserve plugin deps
authorAlex Crichton <alex@alexcrichton.com>
Tue, 29 Jul 2014 02:35:08 +0000 (19:35 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 29 Jul 2014 02:36:45 +0000 (19:36 -0700)
When copying files over from the old root to the new root on a fresh
compilation, care must be taken to preserve the correct plugin/host version of
each dependency. The previous code copied back over at most one library, but
this commit fixes this behavior by copying over all targets necessary for
compilation.

src/cargo/ops/cargo_rustc/context.rs
src/cargo/ops/cargo_rustc/fingerprint.rs
tests/test_cargo_cross_compile.rs

index 9f19fab972bb4b50ac2b4309336db9ec6c298bcc..ad078865b21cc84560b7a2795a39ca9002e089d0 100644 (file)
@@ -233,4 +233,18 @@ impl PlatformRequirement {
             _ => PluginAndTarget,
         }
     }
+
+    pub fn is_target(&self) -> bool {
+        match *self {
+            Target | PluginAndTarget => true,
+            Plugin => false
+        }
+    }
+
+    pub fn is_plugin(&self) -> bool {
+        match *self {
+            Plugin | PluginAndTarget => true,
+            Target => false
+        }
+    }
 }
index f8c82df7e3f76e0304957c81c459923c3b42fdba..6c5f80656dfd4eb8b3ab3097bb238db503545849 100644 (file)
@@ -21,8 +21,9 @@ use super::context::Context;
 /// The third part of the tuple is a job to run when a package is discovered to
 /// be fresh to ensure that all of its artifacts are moved to the correct
 /// location.
-pub fn prepare(cx: &mut Context, pkg: &Package,
-               targets: &[&Target]) -> CargoResult<(Freshness, Job, Job)> {
+pub fn prepare<'a, 'b>(cx: &mut Context<'a, 'b>, pkg: &'a Package,
+                       targets: &[&'a Target])
+                       -> CargoResult<(Freshness, Job, Job)> {
     let filename = format!(".{}.{}.fingerprint", pkg.get_name(),
                            short_hash(pkg.get_package_id()));
     let filename = filename.as_slice();
@@ -57,11 +58,20 @@ pub fn prepare(cx: &mut Context, pkg: &Package,
 
     for &target in targets.iter() {
         if target.get_profile().is_doc() { continue }
-        let layout = cx.layout(target.get_profile().is_plugin());
+        let target_layout = cx.layout(false);
+        let plugin_layout = cx.layout(true);
+        let req = cx.get_requirement(pkg, target);
+
         for filename in cx.target_filenames(target).iter() {
             let filename = filename.as_slice();
-            pairs.push((layout.old_root().join(filename),
-                        layout.root().join(filename)));
+            if req.is_target() {
+                pairs.push((target_layout.old_root().join(filename),
+                            target_layout.root().join(filename)));
+            }
+            if req.is_plugin() && plugin_layout.root() != target_layout.root() {
+                pairs.push((plugin_layout.old_root().join(filename),
+                            plugin_layout.root().join(filename)));
+            }
         }
     }
     let move_old = Job::new(proc() {
index 7e2fe4d7e5534bb7d1f5d8944fd3cfa01eff1de6..f5c4601c35a51d8214829cac1baa5d9a32d96306 100644 (file)
@@ -7,7 +7,7 @@ use std::os;
 use std::path;
 
 use support::{project, execs, basic_bin_manifest};
-use support::{RUNNING, COMPILING};
+use support::{RUNNING, COMPILING, cargo_dir};
 use hamcrest::{assert_that, existing_file};
 use cargo::util::process;
 
@@ -226,6 +226,9 @@ test!(plugin_to_the_max {
     let target = alternate();
     assert_that(foo.cargo_process("cargo-build").arg("--target").arg(target),
                 execs().with_status(0));
+    assert_that(foo.process(cargo_dir().join("cargo-build"))
+                   .arg("--target").arg(target),
+                execs().with_status(0));
     assert_that(&foo.target_bin(target, "foo"), existing_file());
 
     assert_that(